/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jollylengkono.skripsi.Comments.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import jollylengkono.skripsi.Comments.form.CommentsCreateForm;
import jollylengkono.skripsi.dao.CommentsDao;
import jollylengkono.skripsi.dao.KnowledgeBasesDao;
import jollylengkono.skripsi.model.Comments;
import jollylengkono.skripsi.model.KnowledgeBases;
import jollylengkono.skripsi.model.Members;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author hp02
 */
public class CommentsCreate extends Action {
    private String FORWARD;
    private int STATE;
    
    public CommentsCreate() {
    }

    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form, 
            HttpServletRequest request, HttpServletResponse response) {
        HttpSession sess = request.getSession(true);
        Members member = (Members) sess.getAttribute("memberSessObject");
        CommentsCreateForm commentForm = (CommentsCreateForm) form;
        Comments comment = new Comments();
        comment.setComment(commentForm.getComment());
        comment.setCommentator(member);
        comment.setDatePost(commentForm.getDatePost());
        comment.setDatePublish(commentForm.getDatePublish());
        comment.setKnowledgeBase((KnowledgeBases) new KnowledgeBasesDao().read(commentForm.getIdKnowledgeBase()));
        comment.setReplyFor((Comments) new CommentsDao().read(commentForm.getReplyFor()));
        comment.setStatus(commentForm.getStatus());
        this.STATE = new CommentsDao().create(comment);
        if (this.STATE==1) {
            this.FORWARD="success";
        } else {
            this.FORWARD="FAIL";
        }
        return mapping.findForward(FORWARD);
    }

}
